package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Connection;

@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Autowired
      private AccountDao accountDao;

/*下面用的方式不好,每个方法都得添加事务控制,虽然具体事务操作已经简化,写在了专门的事务管理类中
*
* */

    @Override
    //该方法上需要事务就给他加一个注解
    @Transactional
    public void transfer(int from, int to, double money) {


            accountDao.add(to,money);

            accountDao.sub(from,money);


    }

    @Override
    public void delete(int id) {

            accountDao.delete(id);

    }


    @Override
    public void add(Account account) {

        accountDao.save(account);

    }

    @Override
    public Account findById(int id) {


        return accountDao.findById(id);
    }
}
